package projectServlet;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import dao.DAOException;
import dao.EmployeeDAOFactory;
import dao.mysql.EmployeeDAOFactoryImpl;
import dto.UserDTO;

/**
 * Servlet implementation class ApplyLeavePreSet
 */
@WebServlet("/ApplyLeavePreSet")
public class ApplyLeavePreSet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ApplyLeavePreSet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doProcess(request,response);	
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doProcess(request,response);
	}

	private void doProcess(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		EmployeeDAOFactory eFactory = new EmployeeDAOFactoryImpl();
		UserDTO			   user     = new UserDTO();
		
		String SUserID = (String) request.getSession().getAttribute("id");
		int	   UserID  = Integer.parseInt(SUserID);
		
		try {
			user = eFactory.getEmployeeDAO().findUser(UserID);
		} catch (DAOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		request.setAttribute("UserInfo",user);
		
		RequestDispatcher rd = request.getRequestDispatcher("/ApplyLeave.jsp");
		rd.forward(request, response);	
		// TODO Auto-generated method stub
	}

}
